//
//  LeftMenuTableViewCell.m
//  HTP
//
//  Created by admin on 15/10/31.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "LeftMenuTableViewCell.h"
#define CELLHEIGHT 35
#define IMAGEWIDTH 18
#define PADDING 5
#define CELLWIDTH (ScreenWidth - 100)
#define LINEIMAGEHEIGHT 2


@interface LeftMenuTableViewCell()
@property (nonatomic,retain)  UIImageView    *iconImg;
@property (nonatomic,retain)  UILabel        *titleLbl;
@property (nonatomic,retain)  NSNumber       *isFirst;
@property (nonatomic,retain)  UIImageView    *lineImg;

@property (nonatomic,retain) NSDictionary *leftDic;
@end

@implementation LeftMenuTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self _initUI];
    }
    return self;
}
-(void)_initUI{
    [self setBackgroundColor:[UIColor clearColor]];
    _iconImg            = [[UIImageView alloc] init];
    [_iconImg setBackgroundColor:[UIColor clearColor]];
    [self.contentView addSubview:_iconImg];
    
    _titleLbl                   = [[UILabel alloc] init];
    _titleLbl.textColor         = [UIColor whiteColor];
    _titleLbl.font              = [UIFont systemFontOfSize:15];
    _titleLbl.textAlignment     = _TEXT_ALIGN_LEFT;
    _titleLbl.backgroundColor   = [UIColor clearColor];
    [_titleLbl sizeToFit];
    [self.contentView addSubview:_titleLbl];
    
    _lineImg = [[UIImageView alloc] init];
    [_lineImg setBackgroundColor:[UIColor clearColor]];
    [self.contentView addSubview:_lineImg];
    
}
-(void)layoutSubviews{
    [_iconImg setFrame:CGRectMake(PADDING * 4, PADDING, IMAGEWIDTH, IMAGEWIDTH)];
    
    
    [_titleLbl setFrame:CGRectMake(PADDING * 4 + IMAGEWIDTH + PADDING * 6, 0, CELLWIDTH - 10 -IMAGEWIDTH - PADDING *6, CELLHEIGHT - LINEIMAGEHEIGHT)];
    
    [_lineImg setFrame:CGRectMake(PADDING * 4, CELLHEIGHT - LINEIMAGEHEIGHT, CELLWIDTH - PADDING * 8, LINEIMAGEHEIGHT)];
}

-(void)setCellData:(id)cellData{
    _leftDic = (NSDictionary *)cellData;

    [_iconImg setImage:[UIImage imageNamed:_leftDic[ICONIMAGE]]];
    
    [_titleLbl setText:_leftDic[TITLE]];
    
    if ([_leftDic[ISFIRST] integerValue] == 1) {
//        [_lineImg setBackgroundColor:[UIColor greenColor]];
        if ( _lineImg.superview) {
            
        }else{
            [self.contentView addSubview:_lineImg];
        }
        [_lineImg setImage:[UIImage imageNamed:@"menuLine"]];
    }else{
        [_lineImg removeFromSuperview];
    }
}
-(void)setLeftDic:(NSDictionary *)leftDic{
    _leftDic = leftDic;
    [_iconImg setImage:[UIImage imageNamed:_leftDic[ICONIMAGE]]];
    
    [_titleLbl setText:_leftDic[TITLE]];

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    [self setBackgroundColor:[UIColor clearColor]];
    // Configure the view for the selected state
}

@end
